package com.hxy.user.controller;

import com.hxy.basic.exception.BusinessExcpetion;
import com.hxy.basic.query.util.AjaxResult;
import com.hxy.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {

    @Autowired
    private IUserService userService;

    @PostMapping("/smsCode")
    public AjaxResult sendSmsCode(@RequestBody Map<String,String> map){
        try {
            String phone = map.get("phone");
            userService.sendSms(phone);
            return new AjaxResult();
        } catch (BusinessExcpetion e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("发送失败"+e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("系统错误"+e.getMessage());
        }
    }
    @PostMapping("/binderCode")
    public AjaxResult sendBinderCode(@RequestBody Map<String,String> map){
        try {
            String phone = map.get("phone");
            userService.sendBinderCode(phone);
            return new AjaxResult();
        } catch (BusinessExcpetion e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("发送失败"+e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("系统错误"+e.getMessage());
        }
    }


}
